From 68fd7614dbb39da0ec68c7aa4b09bb4f316e2807 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Mon, 26 Sep 2005 19:13:57 +0100 Subject: [PATCH] Move non-transactional and non-idempotent code out of xenstore transaction retry loops in our device drivers. Otherwise things get very smelly if a transaction fails and is retried. Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/xenbus.c | 17 ++++---- .../drivers/xen/blkfront/blkfront.c | 31 +++++++-------- .../drivers/xen/netfront/netfront.c | 31 +++++++-------- .../drivers/xen/tpmback/xenbus.c | 39 +++++++++---------- .../drivers/xen/tpmfront/tpmfront.c | 31 +++++++-------- 5 files changed, 73 insertions(+), 76 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c index ba64721bd6..c68e7f545a 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c @@ -80,6 +80,15 @@ static void frontend_changed(struct xenbus_watch *watch, const char *node) return; } + /* Map the shared frame, irq etc. */ + err = blkif_map(be->blkif, ring_ref, evtchn); + if (err) { + xenbus_dev_error(be->dev, err, "mapping ring-ref %lu port %u", + ring_ref, evtchn); + return; + } + /* XXX From here on should 'blkif_unmap' on error. */ + again: /* Supply the information about the device the frontend needs */ err = xenbus_transaction_start(); @@ -112,14 +121,6 @@ again: goto abort; } - /* Map the shared frame, irq etc. */ - err = blkif_map(be->blkif, ring_ref, evtchn); - if (err) { - xenbus_dev_error(be->dev, err, "mapping ring-ref %lu port %u", - ring_ref, evtchn); - goto abort; - } - err = xenbus_transaction_end(0); if (err == -EAGAIN) goto again; diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c index 598fecc3d1..9d5b44d26c 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -591,17 +591,6 @@ again: goto abort_transaction; } - info->backend = backend; - backend = NULL; - - info->watch.node = info->backend; - info->watch.callback = watch_for_status; - err = register_xenbus_watch(&info->watch); - if (err) { - message = "registering watch on backend"; - goto abort_transaction; - } - err = xenbus_transaction_end(0); if (err) { if (err == -EAGAIN) @@ -610,10 +599,17 @@ again: goto destroy_blkring; } - out: - if (backend) - kfree(backend); - return err; + info->watch.node = backend; + info->watch.callback = watch_for_status; + err = register_xenbus_watch(&info->watch); + if (err) { + message = "registering watch on backend"; + goto destroy_blkring; + } + + info->backend = backend; + + return 0; abort_transaction: xenbus_transaction_end(1); @@ -621,7 +617,10 @@ again: xenbus_dev_error(dev, err, "%s", message); destroy_blkring: blkif_free(info); - goto out; + out: + if (backend) + kfree(backend); + return err; } /* Setup supplies the backend dir, virtual device. diff --git a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c index b7273a5c51..9ddcd15f41 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @@ -1148,17 +1148,6 @@ again: goto abort_transaction; } - info->backend = backend; - backend = NULL; - - info->watch.node = info->backend; - info->watch.callback = watch_for_status; - err = register_xenbus_watch(&info->watch); - if (err) { - message = "registering watch on backend"; - goto abort_transaction; - } - err = xenbus_transaction_end(0); if (err) { if (err == -EAGAIN) @@ -1167,12 +1156,19 @@ again: goto destroy_ring; } + info->watch.node = backend; + info->watch.callback = watch_for_status; + err = register_xenbus_watch(&info->watch); + if (err) { + message = "registering watch on backend"; + goto destroy_ring; + } + + info->backend = backend; + netif_state = NETIF_STATE_CONNECTED; - out: - if (backend) - kfree(backend); - return err; + return 0; abort_transaction: xenbus_transaction_end(1); @@ -1180,7 +1176,10 @@ again: xenbus_dev_error(dev, err, "%s", message); destroy_ring: shutdown_device(info); - goto out; + out: + if (backend) + kfree(backend); + return err; } /* Setup supplies the backend dir, virtual device. diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c index c9c417cabd..48d56745f5 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c @@ -88,31 +88,12 @@ static void frontend_changed(struct xenbus_watch *watch, const char *node) return; } - - /* - * Tell the front-end that we are ready to go - - * unless something bad happens - */ -again: - err = xenbus_transaction_start(); - if (err) { - xenbus_dev_error(be->dev, err, "starting transaction"); - return; - } - - err = xenbus_printf(be->dev->nodename, - "ready", "%lu", ready); - if (err) { - xenbus_dev_error(be->dev, err, "writing 'ready'"); - goto abort; - } - err = tpmif_map(be->tpmif, ringref, evtchn); if (err) { xenbus_dev_error(be->dev, err, "mapping shared-frame %lu port %u", ringref, evtchn); - goto abort; + return; } err = tpmif_vtpm_open(be->tpmif, @@ -125,6 +106,24 @@ again: * Should close down this device and notify FE * about closure. */ + return; + } + + /* + * Tell the front-end that we are ready to go - + * unless something bad happens + */ +again: + err = xenbus_transaction_start(); + if (err) { + xenbus_dev_error(be->dev, err, "starting transaction"); + return; + } + + err = xenbus_printf(be->dev->nodename, + "ready", "%lu", ready); + if (err) { + xenbus_dev_error(be->dev, err, "writing 'ready'"); goto abort; } diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c index 43ae40bdce..0bd6114f43 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c @@ -352,17 +352,6 @@ again: goto abort_transaction; } - info->backend = backend; - backend = NULL; - - info->watch.node = info->backend; - info->watch.callback = watch_for_status; - err = register_xenbus_watch(&info->watch); - if (err) { - message = "registering watch on backend"; - goto abort_transaction; - } - err = xenbus_transaction_end(0); if (err == -EAGAIN) goto again; @@ -371,10 +360,17 @@ again: goto destroy_tpmring; } -out: - if (backend) - kfree(backend); - return err; + info->watch.node = backend; + info->watch.callback = watch_for_status; + err = register_xenbus_watch(&info->watch); + if (err) { + message = "registering watch on backend"; + goto destroy_tpmring; + } + + info->backend = backend; + + return 0; abort_transaction: xenbus_transaction_end(1); @@ -382,7 +378,10 @@ abort_transaction: xenbus_dev_error(dev, err, "%s", message); destroy_tpmring: destroy_tpmring(info, &my_private); - goto out; +out: + if (backend) + kfree(backend); + return err; } -- 2.30.2